<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>物资入库申请</title>

		<link rel="stylesheet" href="../css/index.css">
		<script src="../js/vue.min.js"></script>
		<script src="../js/elementui.js"></script>
		<script src="../js/axios.min.js"></script>
		<script src="../js/mycommon.js"></script>

	</head>

	<body>

		<div id="app">

			<el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="120px">

				<el-form-item label="物资所属品类" prop="field105">
					<el-cascader v-model="formData.field105" :options="field105Options"
						:props="{ 'value':'id','label': 'materialname' }" :style="{width: '100%'}"
						placeholder="请选择物资所属品类" clearable @change="handleEdit"></el-cascader>
				</el-form-item>
				<el-form-item label="所属仓库" prop="warehouseidall">
					<el-cascader v-model="formData.warehouseidall" :options="warehouseidOptions"
						:props="{ 'value':'aid','label': 'warehouse' }" :style="{width: '100%'}" placeholder="请选择所属仓库"
						clearable></el-cascader>
				</el-form-item>
				<el-form-item label="物资数量" prop="content">
					<el-input v-model="formData.content" placeholder="请输入物资数量" clearable
						:style="{width: '100%'}"></el-input>
				</el-form-item>
				<el-form-item label="备注" prop="remarks">
					<el-input v-model="formData.remarks" placeholder="请输入备注" clearable
						:style="{width: '100%'}"></el-input>
				</el-form-item>
				<el-form-item size="large">
					<el-button type="primary" @click="submitForm">提交</el-button>
					<el-button @click="resetForm">重置</el-button>
				</el-form-item>
			</el-form>

		</div>

		<script>
			var vue = new Vue({
				components: {},
				props: [],
				el: "#app",
				data: {
					warehouseidOptions: [],
					formData: {
						field105: [],
						codematerial: "",
						warehouseidall: [],
						warehouseid: '',
						areaid: '',
						shelvesid: '',
						content: undefined,
						remarks: undefined,
					},
					rules: {

						field105: [{
							required: true,
							type: 'array',
							message: '请至少选择一个物资所属品类',
							trigger: 'change'
						}],
						content: [{
							required: true,
							message: '请输入物资数量',
							trigger: 'blur'
						}],
						remark: [],
					},
					field105Options: [],

				},
				computed: {},
				watch: {},
				created() {},
				mounted() {
					this.getParentMent()
					this.getCode()
				},
				methods: {
					submitForm() {
						//alert(JSON.stringify(this.formData));
						this.formData.warehouseid = this.formData.warehouseidall[0].replaceAll("a", "")
						this.formData.areaid = this.formData.warehouseidall[1].replaceAll("b", "")
						this.formData.shelvesid = this.formData.warehouseidall[2].replaceAll("c", "")

						//数据提交
						var that = this
						axios.post(HTTP + "materialstor/add",
							this.formData
						).then(function(res) {
							//alert(JSON.stringify(res));
							if (res.data.code == 200) {
								//提交
								that.$message('提交成功')

							}
						}).catch(err => {
							console.log(err)
						});
					},
					resetForm() {
						this.$refs['elForm'].resetFields()
					},
					getParentMent() {
						//获取仓库信息
						var that = this
						axios.post(HTTP + "warehouse/selectallmaterial").then(function(res) {
							// alert(JSON.stringify(res.data.data.list));
							let jsontree = arrayToTree2(res.data.data.list)
							//alert(JSON.stringify(jsontree));
							that.warehouseidOptions = jsontree
						}).catch(err => {
							console.log(err)
						});
					},
					handleEdit(v) {
						//物资编码获取
						let codematerialid = v[2];
						// alert(codematerialid);
						var that = this
						axios.post(HTTP + "code/codematerialid", {
							"id": codematerialid
						}).then(function(res) {
							//alert(JSON.stringify(res));
							that.formData.codematerial = res.data.data.byid.codematerial
							//alert(JSON.stringify(that.formData.codematerial));
						}).catch(err => {
							console.log(err)
						});


					},
					getCode() {
						//获取物资分类信息
						var that = this
						axios.post(HTTP + "code/warecategory").then(function(res) {
							//alert(JSON.stringify(res.data.data.list));
							let jsontree = arrayToTree3(res.data.data.list)
							//alert(JSON.stringify(jsontree));
							that.field105Options = jsontree
						}).catch(err => {
							console.log(err)
						});
					}
				}
			})
		</script>

	</body>

</html>